import subprocess


class Base_Info():
    def __init__(self):
        self.info = {}

    def get_system_name(self):
        cmd = 'lsb_release -a|grep Description'
        ret = self.run_cmd(cmd).split(":")[1].strip('\t')
        system_name = {'system_name': ret}
        self.info.update(system_name)
        return system_name

    def run_cmd(self, cmd):
        ret = subprocess.getoutput(cmd)
        return ret

    def get_computer_name(self):
        cmd = "cat /proc/cpuinfo |grep 'model name'" \
            + "|awk "+"'"+"NR==1{"+"print}"+"'"+"|awk " + \
            "'"+"{split($0,a,"+'":"'+");print a[2]}"+"'"
        ret = self.run_cmd(cmd)
        processor_name = {"processor_name": ret}
        self.info.update(processor_name)
        return processor_name

    def get_hotpot_name(self):
        cmd1 = "dpkg -l |grep hotpot |awk " + "'{print $2}'"
        cmd2 = "dpkg -l |grep hotpot |awk " + "'{print $3}'"
        ret1 = subprocess.getoutput(cmd1).split()
        ret2 = subprocess.getoutput(cmd2).split()
        hotpot = dict(zip(ret1, ret2))
        hotpot = {'hotpot': hotpot}
        self.info.update(hotpot)
        return hotpot

    def get_license(self):
        cmd1 = "dpkg -l |grep nfs-license |awk " + "'{print $2}'"
        cmd2 = "dpkg -l |grep nfs-license |awk " + "'{print $3}'"
        ret1 = subprocess.getoutput(cmd1).split()
        ret2 = subprocess.getoutput(cmd2).split()
        nfs_license = dict(zip(ret1, ret2))
        nfs_license = {'nfs-license': nfs_license}
        self.info.update(nfs_license)
        return nfs_license

    def base_info(self):
        self.get_system_name()
        self.get_computer_name()
        self.get_hotpot_name()
        self.get_license()
        return self.info